package com.ihrm.company.service.Impl;

import com.ihrm.domain.company.Company;
import com.ihrm.common.entity.Result;
import com.ihrm.common.utils.IdWorker;
import com.ihrm.company.dao.CompanyDao;
import com.ihrm.company.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    private CompanyDao companyDao;

    @Override
    public Result add(Company company) {
        company.setId(new IdWorker().nextId() + "");
        company.setCreateTime(new Date());
        company.setState(1);//启用
        company.setAuditState("0"); //待审核
        company.setBalance(0d);
        Integer num = companyDao.add(company);
        if (num > 0) {
            return Result.SUCCESS();
        }
        return Result.FAIL();
    }

    @Override
    public List<Company> select() {
        return companyDao.select();
    }

    @Override
    public Company getCompanyById(String id) {
        return companyDao.getCompanyById(id);
    }

    @Override
    public Integer updateCompany(String id, Company company) {
        company.setId(id);
        return companyDao.updateCompany(company);
    }
}
